package com.jsj.servlet.ch3;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/HelloServlet4")
public class HelloServlet4 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public HelloServlet4() {
        super();
    }
    
    @Override
    public void init(ServletConfig config) throws ServletException {
    	super.init(config);
    	String username=config.getInitParameter("username");
    	String password=config.getInitParameter("password");    	
    	System.out.println("username===="+username+"\tpassword=="+password);
    	
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		
		ServletContext context=super.getServletContext();
		Integer count=(Integer) context.getAttribute("count");
		if(count==null) {
			count=1;
		}else {
			count=count+1;
		}
		context.setAttribute("count", count);
		PrintWriter out=response.getWriter();
		out.println("网站访问次数："+count);
		
		System.out.println(request.getMethod());
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
